package com.quanfaqiang.demo1.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.quanfaqiang.demo1.pojo.OperateLog;
import com.quanfaqiang.demo1.pojo.Result;
import com.quanfaqiang.demo1.service.OperateLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;
import java.time.LocalDateTime;
import java.util.List;

@RestController
@CrossOrigin()
@RequestMapping("/operatelog")
public class OperateLogController {
    @Autowired
    private OperateLogService operateLogService;

    @GetMapping("/selectAll")
    public Result selectAll(Integer currentPage, Integer pageSize) {
        System.out.println(currentPage+":"+pageSize+"-----------------------------------");
        Page<OperateLog> List = operateLogService.selectAll(currentPage, pageSize);
        return Result.success(List);
    }


    @GetMapping("/serch")
    public Result serch(String operateUser,  @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime startTime,
                                @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime endTime,
                                String operate,String operateName,Integer currentPage, Integer pageSize) {
        Page<OperateLog> typeList = operateLogService.serchTypeName(operateUser,startTime,endTime,operate,operateName,currentPage,pageSize);
        System.out.println(typeList);
        return Result.success(typeList);
    }


//    @DeleteLog
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id) {
        operateLogService.delete(id);
        return Result.success("删除成功");
    }

//    @DeleteLog
    @DeleteMapping("/deleteMore/{ids}")
    public Result deleteIds(@PathVariable List<Integer> ids) {
        System.out.println(ids+"sssssssssssssssssss");
        operateLogService.deleteIds(ids);
        return Result.success("删除成功");
    }

    @GetMapping("selectOperate")
    public Result selectOperate(){
        List<String>  list=operateLogService.selectOperate();
        return Result.success(list);

    }

    @GetMapping("selectOperateName")
    public Result selectOperateName(){
        List<String>  list=operateLogService.selectOperateName();
        return Result.success(list);
    }


}
